﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Buccaneer;
using Buccaneer.Types;
using Buccontrols;

namespace Buccaneer
{
    public partial class LoadPluginForm : PluginForm
    {
        public LoadPluginForm(PluginCouple parentCouple)
        {
            InitializeComponent();

            ParentCouple = parentCouple;
        }

        private void btn_loadNewPlugin_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Title = "Choose a plugin to load";
            ofd.InitialDirectory = Options.PluginsFolder;
            ofd.Filter = "Buccaneer Plugin | *.dll";
            ofd.ShowDialog();
            if (ofd.SafeFileName == "") return;
            base.Act("loadlib", new string[]
            {
                ofd.SafeFileName,
                ofd.FileName.Replace(ofd.SafeFileName, "")
            });
            base.Act("loadplugin", new string[]
            {
                ofd.SafeFileName.Replace(".dll", "")
            });
        }

        private void LoadPluginForm_Load(object sender, EventArgs e)
        {
            cbx_loadedPlugins.Items.Clear();
            foreach (AvailablePlugin pluginOn in MainProgram.Plugins.AvailablePlugins)
            {
                cbx_loadedPlugins.Items.Add(pluginOn.Instance.Name);
            }
        }

        private void btn_addPlugin_Click(object sender, EventArgs e)
        {
            if (cbx_loadedPlugins.SelectedItem == null) return;
            base.Act("loadplugin", new string[]
            {
                cbx_loadedPlugins.SelectedItem.ToString()
            });
        }

        private void cbx_loadedPlugins_Click(object sender, EventArgs e)
        {
            cbx_loadedPlugins.Items.Clear();
            foreach (string pluginOn in MainProgram.Plugins.AvailablePluginTypes)
            {
                cbx_loadedPlugins.Items.Add(pluginOn);
            }
            Options.WriteComment("(i) Reloaded plugins");
        }
    }
}
